package com.wondertek.poms.dao.po;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.wondertek.poms.common.constant.CurrentUser;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Proxy;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;

/**
 * @author chenjijiang
 * 一级产品
 */
@Data
@Entity
@Table(name = "FIRST_PRODUCT_INFO_PACKAGE")
@DynamicUpdate
@DynamicInsert
@Proxy(lazy = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class FirstProductInfoPackage implements Serializable {
	private static final long serialVersionUID = -2355753841595426710L;

	/**
	 * <b>Fields</b> firstProductId :一级产品Id
	 */
	@Id
	@Column(name = "FIRST_PRODUCT_ID")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "FIRST_PRODUCT_INFO_PACKAGE_SEQ")
	@SequenceGenerator(name = "FIRST_PRODUCT_INFO_PACKAGE_SEQ", sequenceName = "FIRST_PRODUCT_INFO_PACKAGE_SEQ", allocationSize = 1)
	private Long firstProductId;

	/**
	 * <b>Fields</b> createDate :创建时间
	 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@Column(name = "CREATE_DATE")
	private Date createDate;

	/**
	 * <b>Fields</b> description : 产品包描述
	 */
	@Column(name = "DESCRIPTION")
	private String description;

	/**
	 * <b>Fields</b> firstProductAlias : 一级产品别名
	 */
	@Column(name = "FIRST_PRODUCT_ALIAS")
	private String firstProductAlias;

	/**
	 * <b>Fields</b> firstProductName : 一级产品名称
	 */
	@Column(name = "FIRST_PRODUCT_NAME")
	private String firstProductName;

	/**
	 * <b>Fields</b> lastOperator : 最后操作人
	 */
	@Column(name = "LAST_OPERATOR")
	private String lastOperator;

	/**
	 * <b>Fields</b> lastUpdateDate : 最后更新时间
	 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@Column(name = "LAST_UPDATE_DATE")
	private Date lastUpdateDate;

	/**
	 * <b>Fields</b> status :状态  //0:待发布   1:已发布  2：已撤回  //目前这个字段展示不需要，默认为1
	 */
	@Column(name = "STATUS")
	private String status;

	/**
	 *  更新操作人个更新时间
	 * @param firstProductInfoPackage 一级产品
	 */
	public static void putTimeAndUser(FirstProductInfoPackage firstProductInfoPackage) {
		if (firstProductInfoPackage.firstProductId == null) {
			firstProductInfoPackage.setLastOperator(CurrentUser.currUserName());
			firstProductInfoPackage.setCreateDate(new Date());
		}
		firstProductInfoPackage.setLastOperator(CurrentUser.currUserName());
		firstProductInfoPackage.setLastUpdateDate(new Date());
	}


}
